<?php
	
	$serviceURL = "http://labs.ideeinc.com/coloursearch/services/rest/?method=color.search&quantity=1&page=0&imageset=flickr&colors=";
	
	define ('HOSTNAME', $serviceURL);

	$cor = $_GET['cor'];
	//$cor = 'aaaaaa';
	$url = HOSTNAME. $cor ;

	$session = curl_init($url);

	curl_setopt($session, CURLOPT_HEADER, false);
	curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

	$fotoJSON = curl_exec($session);
	$fotoURL =  get_object_vars(json_decode($fotoJSON));
	curl_close($session);
	$session = curl_init($fotoURL['result'][0][1]);

	curl_setopt($session, CURLOPT_HEADER, false);
	curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

	$foto = curl_exec($session);

	header("Content-Type: Image");
	
	$image_p = imagecreatetruecolor(75, 75);
	$white = imagecolorallocate($image_p, 255, 255, 255);
	imagefill($image_p, 0, 0, $white);
	$image = @imagecreatefromjpeg($cor);
	@imagecopyresampled($image, $foto, 0, 0, 0, 0, 75, 75, 75, 75);
	
	echo $foto;
	curl_close($session);
?>